import { makeAutoObservable } from 'mobx';
import { ISkillAddItem , ISkillLabel ,interRecord} from '@/utils/interface';
import { addPostSkill , getSkillLabel , getSkillDetail, DeleteSkillListItem , getSkillList,getinterDetail} from '@/services/index';
// import addPostSkill from '@/pages/teachers/addPostSkill';

class Skill{
    constructor(){
        makeAutoObservable(this)
    };

    skillLabel : ISkillLabel[] = [];
    
    skillAddItem: ISkillAddItem = {
        "majorId": "",
        "name": "",
        "stationVersion": 1,
        "userName": "郭老师",
        "stationVersionId": "",
        "majorName": "",
        "stationLevelList": [
            {
                "describes": "123",
                "salaryList": [
                   5000,
                   20000
                ],
                "stationLevel": 1,
                "stationTask": "456",
                "level_name": "初级",
                "disabled": false
            },
            {
                "describes": "",
                "salaryList": [
                    12000,
                    20000
                ],
                "stationLevel": 2,
                "level_name": "中级",
                "stationTask": "",
                "disabled": false
            },
            {
                "describes": "",
                "salaryList": [
                    20000,
                    40000
                ],
                "stationLevel": 3,
                "stationTask": "",
                "level_name": "高级",
                "disabled": false
            }
        ]
    }
    async getSkillLabel(){
        let result = await getSkillLabel();
        if(result.data){
            this.skillLabel = result.data;
        }
    }
    // 添加岗位
    async addPostSkill(params: ISkillAddItem){
        // 结构
        let {describes, majorId, name, salaryList, stationTask, stationVersion} = params;

        // 先获取 价位
        let stationLevelList = this.skillAddItem.stationLevelList;

        // 给第一个重新赋值 ==》因为他是数组 无奈 ╮(╯▽╰)╭
        stationLevelList[0] = {...stationLevelList[0], salaryList: salaryList as number[], describes: describes as string, stationTask: stationTask as string};
        
        // 深拷贝的值 传输过来的值
        this.skillAddItem = {...this.skillAddItem, majorId, name, stationVersion, stationLevelList};
        
        // 调用添加链接
        let result = await addPostSkill(this.skillAddItem);

        // 容错
        if (result.data){
            this.skillAddItem = result.data;      
            return result.data.stationVersionId;
        }
    }

    // 获取岗位详情
    async getSkillDetail(stationVersionId : string){
        let result = await getSkillDetail(stationVersionId);
        // 容错
        if(result.data){
            this.skillAddItem = result.data;
        }
    }
    

    // 删除其中一项
    async DeleteListItem( stationVersionId : string ){
        let result = await DeleteSkillListItem( stationVersionId );
        console.log(result);
        this.getSkillLabel();
    }
    

    // // 查询所有
    // async getSkillList(){
    //     getSkillList(queryParams :).then(res => {
    //         if (res.code == 200) {
    //             setDataSource(res.rows);
    //         }

    //     })
    // }
   
}

export default new Skill;